package com.itheima.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.domain.po.Dept;
import com.itheima.mapper.DeptMapper;
import com.itheima.mapper.EmpMapper;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {

    @Autowired
    private EmpMapper empMapper;

    /**
     * 根据id删除部门
     *
     * @param id 部门id
     */
    @Override
    public void removeDeptById(Integer id) {
        //判断是否有员工
        Integer emp = empMapper.countDeptId((id));
        if (emp > 0) {
            throw new RuntimeException("该部门有员工，不能删除");
        }
        this.removeById(id);
    }
}
